package com.usernet.product.tools;

import java.util.List;

public class Page {
	// 成员变量

	// 当前页
	private int nowpage;
	// 总记录数
	private int countrecord;
	// 总页数
	private int countpage;
	// 当前页记录开始的位置
	private int pageindex;
	// 每页显示的记录数
	public final int PAGESIZE = 10;
	// 索引的sum值 代表的是 google页面中最大显示页数
	private int sumindex = 10;
	// 开始的索引值
	private int startindex;
	// 结束的索引值
	private int endindex;
	// 当前页信息
	private List<?> allentities;

	// 构造器
	public Page() {
	}

	public Page(int countrecord, int nowpage) {
		// 计算当前页
		this.nowpage = nowpage;
		// 计算出当前页开始的位置
		this.pageindex = (nowpage - 1) * PAGESIZE;
		// 计算总页数
		this.countrecord = countrecord;
		if (this.countrecord % this.PAGESIZE == 0) {
			this.countpage = this.countrecord / this.PAGESIZE;
		} else {
			this.countpage = this.countrecord / this.PAGESIZE + 1;
		}

		// 计算开始和结束的索引值
		// 当当前页小于等于四时开始的索引值等于一,而结束的索引值分两种情况
		if (this.nowpage <= 4) {
			this.startindex = 1;
			this.endindex = this.sumindex;
			if (endindex > countpage) {
				this.endindex = this.countpage;
			}
		}
		// 当当前页大于四时开始的索引值和结束的索引值均分三种情况
		else if (this.nowpage > 4) {
			this.startindex = nowpage - 2;
			this.endindex = nowpage - 2 + this.sumindex;
			if (endindex > countpage) {
				this.endindex = this.countpage;
			}
		}
	}

	public int getNowpage() {
		return nowpage;
	}

	public void setNowpage(int nowpage) {
		this.nowpage = nowpage;
	}

	public int getCountrecord() {
		return countrecord;
	}

	public void setCountrecord(int countrecord) {
		this.countrecord = countrecord;
	}

	public int getCountpage() {
		return countpage;
	}

	public void setCountpage(int countpage) {
		this.countpage = countpage;
	}

	public int getPageindex() {
		return pageindex;
	}

	public void setPageindex(int pageindex) {
		this.pageindex = pageindex;
	}

	public int getSumindex() {
		return sumindex;
	}

	public void setSumindex(int sumindex) {
		this.sumindex = sumindex;
	}

	public int getStartindex() {
		return startindex;
	}

	public void setStartindex(int startindex) {
		this.startindex = startindex;
	}

	public int getEndindex() {
		return endindex;
	}

	public void setEndindex(int endindex) {
		this.endindex = endindex;
	}

	public List<?> getList() {
		return allentities;
	}

	public void setList(List<?> list) {
		this.allentities = list;
	}
}
